package com.gh.cloud.user.controller;

import com.gh.cloud.commons.core.constant.HttpHeaderNameConstants;
import com.gh.cloud.user.fegin.ProductFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author: guohao
 * @date: 2021-02-01 17:49
 **/
@RequestMapping("/test")
@RestController
public class UserController {

    @Autowired
    private ProductFeign productFeign;

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/getUserById/{id}")
    public Object getUserById(@PathVariable String id, HttpServletRequest request){

        String header = request.getHeader(HttpHeaderNameConstants.TOKEN_HEADER);
        return header;
    }

    @GetMapping(value = "/getProductById/{id}")
    public Object getProductById(@PathVariable String id ){
        System.out.println("用户服务===================port:"+port);
        System.out.println("getProductById/"+id);
        System.out.println("用户服务===================port:"+port);
        return "user-port:"+port+"; result:"+productFeign.getProductById(id);
    }
}
